package com.lxmes.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.base.domain.JcProjectInfo;
import com.lxmes.base.service.IJcProjectInfoService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 项目详情Controller
 * 
 * @author 张志煜
 * @date 2022-08-27
 */
@RestController
@RequestMapping("/base/projectinfo")
public class JcProjectInfoController extends BaseController
{
    @Autowired
    private IJcProjectInfoService jcProjectInfoService;

    /**
     * 查询项目详情列表
     */
    @PreAuthorize("@ss.hasPermi('base:projectinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcProjectInfo jcProjectInfo)
    {
        startPage();
        jcProjectInfo.setDeptId(SecurityUtils.getDeptId());
        List<JcProjectInfo> list = jcProjectInfoService.selectJcProjectInfoList(jcProjectInfo);
        return getDataTable(list);
    }

    /**
     * 导出项目详情列表
     */
    @PreAuthorize("@ss.hasPermi('base:projectinfo:export')")
    @Log(title = "项目详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcProjectInfo jcProjectInfo)
    {
        jcProjectInfo.setDeptId(SecurityUtils.getDeptId());
        List<JcProjectInfo> list = jcProjectInfoService.selectJcProjectInfoList(jcProjectInfo);
        ExcelUtil<JcProjectInfo> util = new ExcelUtil<JcProjectInfo>(JcProjectInfo.class);
        util.exportExcel(response, list, "项目详情数据");
    }

    /**
     * 获取项目详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:projectinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(jcProjectInfoService.selectJcProjectInfoById(id));
    }

    /**
     * 新增项目详情
     */
    @PreAuthorize("@ss.hasPermi('base:projectinfo:add')")
    @Log(title = "项目详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcProjectInfo jcProjectInfo)
    {
        jcProjectInfo.setDeptId(SecurityUtils.getDeptId());
        return toAjax(jcProjectInfoService.insertJcProjectInfo(jcProjectInfo));
    }

    /**
     * 修改项目详情
     */
    @PreAuthorize("@ss.hasPermi('base:projectinfo:edit')")
    @Log(title = "项目详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcProjectInfo jcProjectInfo)
    {
        return toAjax(jcProjectInfoService.updateJcProjectInfo(jcProjectInfo));
    }

    /**
     * 删除项目详情
     */
    @PreAuthorize("@ss.hasPermi('base:projectinfo:remove')")
    @Log(title = "项目详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcProjectInfoService.deleteJcProjectInfoByIds(ids));
    }
}
